package org.example.project.service.impl;

import org.example.project.dao.PostDao;
import org.example.project.entity.Post;
import org.example.project.service.PostService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 岩
 * @Package org.example.project.service.impl
 * @Project MyApp
 * @Name PostServiceImpl
 * @Date 2024-04-27 15:03
 * @Filename PostServiceImpl
 */

@Service("postService")
public class PostServiceImpl implements PostService {
    @Resource
    private PostDao postDao;
    @Override
    public List<Post> queryAll() {
        return this.postDao.queryAll();
    }

    @Override
    public Post queryById(int id) {
        return this.postDao.queryById(id);
    }

    @Override
    public List<Post> queryByTitle(String title) {
        return this.postDao.queryByTitle(title);
    }

    @Override
    public Post insert(Post post) {
        this.postDao.insert(post);
        return this.postDao.queryById(post.getId());
    }

    @Override
    public boolean likePost(int id) {
        return this.postDao.likePost(id) > 0;
    }

    @Override
    public Post update(Post post) {
        this.postDao.update(post);
        return this.postDao.queryById(post.getId());
    }

    @Override
    public boolean delete(int id) {
        // 先删除帖子评论
        this.postDao.deleteCommentsWithPost(id);
        return this.postDao.delete(id) > 0;
    }
}
